

import permission from "@/js_sdk/wa-permission/permission";
/**

@param {string} permissionType 系统权限类型
@param {string} permissionType 权限中文显示名 
@return {boolean} true有，false没有进入引导

**/

export default async function  checkPermissions(permissionType, permissionName){
	 
	      let hasPermission = false
	      
	      // #ifdef APP-PLUS
	      if (permission.isIos) {
	        // iOS系统检查权限
	        hasPermission = permission.judgeIosPermission(permissionType)
	      } else {
	        // Android系统检查权限，需要传入对应的权限常量
	        const androidPermissions = {
	          record: 'android.permission.RECORD_AUDIO',
	          camera: 'android.permission.CAMERA',
	          photoLibrary: 'android.permission.READ_EXTERNAL_STORAGE',
	          contact: 'android.permission.READ_CONTACTS'
	        }
	        
	        const result = await permission.requestAndroidPermission(androidPermissions[permissionType])
	        // Android返回值：1=已授权，0=临时拒绝，-1=永久拒绝
	        hasPermission = result === 1
	      }
	      // #endif
	      
	     // 权限未开启时引导用户
	      if (!hasPermission) {
	        this.$modal.confirm({
	          title: '权限申请',
	          content: `当前功能需要${permissionName}权限，请前往设置开启`,
	          confirmText: '去设置',
	          cancelText: '取消',
	          success: (res) => {
	            if (res.confirm) {
	              // 跳转到应用权限设置页面
	              permission.gotoAppPermissionSetting()
	            }
	          }
	        })
	      }
	      
	      return hasPermission
	    }
	//备用批量检查
	    async function checkAllPermissions() {
	      // 权限配置列表：类型与显示名称的映射
	      const permissions = [
	        { type: 'record', name: '麦克风' },
	        { type: 'camera', name: '相机' },
	        { type: 'photoLibrary', name: '相册' },
	        { type: 'contact', name: '通讯录' }
	      ]
	      
	      // 逐个检查权限
	      for (const item of permissions) {
	        const hasPermission = await this.checkSinglePermission(item.type, item.name)
	        if (!hasPermission) {
	          // 可以根据需求决定是否中断检查
	          // return false
	        }
	      }
	      
	      return true
	    }
	
	
	
	
